#
# 构建 php-fpm 7.1.14
#

FROM e7sky/was:3.7
MAINTAINER joen kai168@126.com


ENV PHP_VERSION 7.1.14
ENV OPENSSL_VERSION 1.0.2j


RUN apk add --no-cache --virtual .build-deps g++ make perl unzip autoconf \
			&& apk add --no-cache --virtual .run-deps libxml2-dev jpeg-dev libpng-dev gd bzip2-dev curl curl-dev freetype-dev zlib-dev pcre-dev \
			&& cd /was/soft && gosu was curl -fSL -O https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz \
			&& cd /was/soft && gosu was curl -fSL -o php-$PHP_VERSION.tar.gz http://hk2.php.net/get/php-$PHP_VERSION.tar.gz/from/this/mirror \
			&& cd /was/soft && gosu was tar xzf openssl-$OPENSSL_VERSION.tar.gz && cd openssl-$OPENSSL_VERSION && gosu was ./config --prefix=/was/run/openssl && gosu was make -j$(getconf _NPROCESSORS_ONLN) && gosu was make install \
			&& cd /was/soft \
			&& gosu was tar xzf php-$PHP_VERSION.tar.gz \
      && cd php-$PHP_VERSION \
      && gosu was ./configure --prefix=/was/run/fpm \
      	--with-config-file-path=/was/run/fpm/etc \
      	--with-fpm-user=was \
      	--with-fpm-group=g_was \
      	--with-openssl=/was/run/openssl \
      	--with-zlib \
				--disable-cgi \
      	--enable-sockets \
				--enable-ftp \
      	--with-curl \
      	--enable-fpm \
      	--enable-zip \
      	--enable-bcmath \
      	--enable-mbstring \
      	--with-gd \
      	--enable-gd-native-ttf \
      	--with-freetype-dir \
      	--with-jpeg-dir \
				--enable-mysqlnd \
      	--with-pdo-mysql \
      	--with-mysqli \
      	--with-mysql \
      && gosu was make -j$(getconf _NPROCESSORS_ONLN) \
      && gosu was make install \
      && gosu was cp php.ini-production /was/run/fpm/etc/php.ini \
      && gosu was sh -c "echo \"date.timezone = PRC\" >> /was/run/fpm/etc/php.ini" \
      && gosu was cp /was/run/fpm/etc/php-fpm.conf.default /was/run/fpm/etc/php-fpm.conf \
      && gosu was sh -c "echo '[global]' >> /was/run/fpm/etc/php-fpm.conf" \
      && gosu was sh -c "echo 'daemonize = no' >> /was/run/fpm/etc/php-fpm.conf" \
      && gosu was sh -c "echo 'error_log = /was/run/fpm/logs/php-fpm.log' >> /was/run/fpm/etc/php-fpm.conf" \
      && gosu was sh -c "echo '[www]' >> /was/run/fpm/etc/php-fpm.conf" \
      && gosu was sh -c "echo 'listen = 9000' >> /was/run/fpm/etc/php-fpm.conf" \
      && gosu was sh -c "echo 'catch_workers_output = yes' >> /was/run/fpm/etc/php-fpm.conf" \
      && gosu was mkdir -p /was/run/fpm/logs \
			# 移除 apk
	 		&& rm -Rf /was/soft/* \
			&& apk del .build-deps 

RUN gosu was cp /was/run/fpm/etc/php-fpm.d/www.conf.default /was/run/fpm/etc/php-fpm.d/www.conf

EXPOSE 9000
CMD ["/was/run/fpm/sbin/php-fpm"]


